// 函数表达式
var localStorageCache = (function(self){
    const prefix = 'one_more_lsc_'
    /** 
     * 增加一个键值对数据
     * @param key 键
     * @param val 值
     * @param expires 过期时间，单位为秒
    */
    self.set = function(key, val, expires) {
        key = prefix + key
        val = JSON.stringify({
            val: val,
            expires: new Date().getTime() + expires * 1000
        })
        window.localStorage.setItem(key, val)
    },

    /**
     * 
     * @param {*} key 
     * @returns 
     */
    self.get = function(key) {
        key = prefix + key
        val = window.localStorage.getItem(key)
        if (!val) {
            return null
        }

        val = JSON.parse(val)
        if (val.expires < new Date().getTime()) {
            window.localStorage.removeItem(key)
            return null
        }

        return val.val
    },

    /**
     * 
     * @param {*} key 
     */
    self.remove = (key) => {
        key = prefix + key
        window.localStorage.removeItem(key)
    }

    return self
}(localStorageCache || {}))
